package zpf.zpf.controller;

import lombok.extern.slf4j.Slf4j;

import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
@Slf4j
public class NonMainThreadTest {

    public static void main(String[] args) throws Exception {
        Thread.sleep(3000);
        log.info("Test start");
        //声明一个StingSelection 对象，并使用String的参数完成实例化；
        StringSelection stringSelection = new StringSelection("我是机器人-allSchool-推广文案..来自按键精灵的复制");
        //使用Toolkit对象的setContents将字符串放到粘贴板中 ；
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
        Robot robot = null ;
        try{
            robot = new Robot();
            robot.setAutoDelay(100);
        }catch(AWTException e){
            log.info("robot初始化错误:",e);
            return ;
        }
        //按下command v键 ；
        robot.keyPress(KeyEvent.VK_META);
        robot.keyPress(KeyEvent.VK_V);
        //command v 键
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_META);
        log.info("Test end");
    }
}